﻿using AutoMapper;
using MediatR;
using T_settlement.API.Application.Command.PayMoneyCommand;
using T_settlement.Domain;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.PayMoneyCommandHandlers
{
    public class AddPayMoneyCommandHandlers:IRequestHandler<AddPayMoneyCommand,int>
    {
        private readonly IPayMoneyRepository payMoneyRepository;
        private readonly IMapper mapper;

        public AddPayMoneyCommandHandlers(IPayMoneyRepository payMoneyRepository, IMediator mediator, IMapper mapper)
        {
            this.payMoneyRepository = payMoneyRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(AddPayMoneyCommand request, CancellationToken cancellationToken)
        {

            var Info = mapper.Map<PayMoney>(request);
            Info.Number = "SY" + DateTime.Now.ToString("yyyyMMddss");
            Info.CheckState = 2;
            return await payMoneyRepository.AddAsync(Info);

            // var Info = new PayMoney();
            // Info.Number = "SY" + DateTime.Now.ToString("yyyyMMddss");
            // Info.Outsourcing=request.Outsourcing;
            // Info.PayType = request.PayType;
            // Info.Tonnage = request.Tonnage;
            // Info.NnitPrice = request.NnitPrice;     
            // Info.Amount = request.Amount;
            // Info.BusinessTime = request.BusinessTime;
            // Info.Attn=request.Attn;
            // Info.CreateDate = request.CreateDate;
            // Info.Remark = request.Remark;
            // Info.CheckState = 2;
            //return await payMoneyRepository.AddAsync(Info);

        }
    }
}
